var prefix = api + "/admin/dict";
var oper = getQueryString('oper')
var id = getQueryString('id')

$(function() {
	renderDictFilter('#systemFlag', 'dict_type')
	$('#oper').val(oper)
	if (oper === 'edit') {
		dictDetail(id)
		$('#type').attr('disabled', true)
	}else{
		$('#systemFlag').val(0) //字典类型只能新增业务类
	}

	jQuery.validator.addMethod("format", function (value, element) {
		var account = /^[a-zA-Z0-9_]*$/;
		return account.test(value);
	}, "只支持字母、数字、下划线");

});

function dictDetail(id){
	$.operate.get(api + '/admin/dict/' + id, function (res) {
		res.data.oper = oper
		applyDrawing('#editForm',res.data)
	}, false)
}

$("#editForm").validate({
	onkeyup : false,
	rules : {
		type: {
			required: true,
			format: true
		},
		description : {
			required: true,
		},
		systemFlag : {
			required: true
		},
	},
	messages: {
		type: {
			required: "请输入字典类型",
		},
		description : {
			required: "请输入字典描述",
		},
		systemFlag : {
			required: "请选择字典类型"
		},
	},
	focusCleanup : true
});
		

function submitHandler() {
	if ($.validate.form()) {
		$.common.ajaxCommitForm($('#editForm'),false);
    	return false;
	}
}